﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace DownloadFiles
{
    public class CommFunc
    {
        public static void SaveTmpData(DataTable dt, string path)
        {
            BinaryFormatter binaryFormatter = new BinaryFormatter();
            using (var stream = new FileStream(path, FileMode.Create, FileAccess.Write))
            {
                binaryFormatter.Serialize(stream, dt);
                //var stream = new StreamWriter(path, false)
            }
        }

        public static DataTable LoadTmpData(string path)
        {
            BinaryFormatter binaryFormatter = new BinaryFormatter();

            using (var stream =File.Open(path, FileMode.Open, FileAccess.Read))
            {
                return binaryFormatter.Deserialize(stream) as DataTable;
            }
        }
    }
}
